package com.onpositive.data.serializer.writers;

import java.util.Date;
import java.util.GregorianCalendar;

import com.onpositive.data.serializer.readers.DefaultReaderFactory;

public class DateWriter extends CollectionWriter<Date>{
	
	private final static Date defaultDate = new Date(0) ;

	public DateWriter() {
		super(Date.class);
	}
	
	@Override
	protected int getItemSize() {
		return 4;
	}
	GregorianCalendar cl=new GregorianCalendar();

	@Override
	protected void writeValue( Date w ) {
		
		cl.setTime(w);
		//int vl=cl.get(GregorianCalendar.YEAR)*366+cl.get(GregorianCalendar.DAY_OF_YEAR);
		int vl=(cl.get(GregorianCalendar.YEAR)<<9)+cl.get(GregorianCalendar.DAY_OF_YEAR) ;
		super.writeIntToStream( vl );
	}

	@Override
	protected Date defaultObject() {
		return defaultDate ;
	}
	
	@Override
	protected int getID()
	{
		return DefaultReaderFactory.RW_ID_DATE  ;				
	}

}
